using Senparc.Weixin.Entities;
using Senparc.Weixin.HttpUtility;
using Senparc.Weixin.MP.AdvancedAPIs.ShakeAround;
using Senparc.Weixin.MP.CommonAPIs;
using System;
using System.Collections.Generic;
namespace Senparc.Weixin.MP.AdvancedAPIs
{
	public static class ShakeAroundApi
	{
		private static string searchDeviceUrl = "https://api.weixin.qq.com/shakearound/device/search?access_token={0}";
		private static string searchPageUrl = "https://api.weixin.qq.com/shakearound/page/search?access_token={0}";
		public static WxJsonResult Register(string accessTokenOrAppId, RegisterData data, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/shakearound/account/register?access_token={0}", accessToken);
				return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static GetAuditStatusResultJson GetAuditStatus(string accessTokenOrAppId)
		{
			return ApiHandlerWapper.TryCommonApi<GetAuditStatusResultJson>(delegate(string accessToken)
			{
				string url = string.Format("https://api.weixin.qq.com/shakearound/account/auditstatus?access_token={0}", accessToken);
				return Get.GetJson<GetAuditStatusResultJson>(url, null);
			}, accessTokenOrAppId, true);
		}
		public static DeviceApplyResultJson DeviceApply(string accessTokenOrAppId, int quantity, string applyReason, string comment = null, long? poiId = null, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<DeviceApplyResultJson>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/shakearound/device/applyid?access_token={0}", accessToken);
				var data = new
				{
					quantity = quantity,
					apply_reason = applyReason,
					comment = comment,
					poi_id = poiId
				};
				return CommonJsonSend.Send<DeviceApplyResultJson>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static WxJsonResult DeviceUpdate(string accessTokenOrAppId, long deviceId, string uuId, long major, long minor, string comment, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/shakearound/device/update?access_token={0}", accessToken);
				var data = new
				{
					device_identifier = new
					{
						device_id = deviceId,
						uuid = uuId,
						major = major,
						minor = minor
					},
					comment = comment
				};
				return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static WxJsonResult DeviceBindLocatoin(string accessTokenOrAppId, long deviceId, string uuId, long major, long minor, long poiId, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/shakearound/device/bindlocation?access_token={0}", accessToken);
				var data = new
				{
					device_identifier = new
					{
						device_id = deviceId,
						uuid = uuId,
						major = major,
						minor = minor
					},
					poi_id = poiId
				};
				return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static DeviceSearchResultJson SearchDeviceById(string accessTokenOrAppId, List<DeviceApply_Data_Device_Identifiers> deviceIdentifiers, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<DeviceSearchResultJson>(delegate(string accessToken)
			{
				var data = new
				{
					device_identifiers = deviceIdentifiers
				};
				return CommonJsonSend.Send<DeviceSearchResultJson>(accessToken, ShakeAroundApi.searchDeviceUrl, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static DeviceSearchResultJson SearchDeviceByRange(string accessTokenOrAppId, int begin, int count, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<DeviceSearchResultJson>(delegate(string accessToken)
			{
				var data = new
				{
					begin,
					count
				};
				return CommonJsonSend.Send<DeviceSearchResultJson>(accessToken, ShakeAroundApi.searchDeviceUrl, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static DeviceSearchResultJson SearchDeviceByApplyId(string accessTokenOrAppId, long applyId, int begin, int count, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<DeviceSearchResultJson>(delegate(string accessToken)
			{
				var data = new
				{
					apply_id = applyId,
					begin = begin,
					count = count
				};
				return CommonJsonSend.Send<DeviceSearchResultJson>(accessToken, ShakeAroundApi.searchDeviceUrl, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static UploadImageResultJson UploadImage(string accessTokenOrAppId, string file, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<UploadImageResultJson>(delegate(string accessToken)
			{
				string url = string.Format("https://api.weixin.qq.com/shakearound/material/add?access_token={0}", accessToken);
				Dictionary<string, string> dictionary = new Dictionary<string, string>();
				dictionary["media"] = file;
				return Post.PostFileGetJson<UploadImageResultJson>(url, null, dictionary, null, null, timeOut);
			}, accessTokenOrAppId, true);
		}
		public static AddPageResultJson AddPage(string accessTokenOrAppId, string title, string description, string pageUrl, string iconUrl, string comment = null, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<AddPageResultJson>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/shakearound/page/add?access_token={0}", accessToken);
				var data = new
				{
					title = title,
					description = description,
					page_url = pageUrl,
					comment = comment,
					icon_url = iconUrl
				};
				return CommonJsonSend.Send<AddPageResultJson>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static UpdatePageResultJson UpdatePage(string accessTokenOrAppId, long pageId, string title, string description, string pageUrl, string iconUrl, string comment = null, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<UpdatePageResultJson>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/shakearound/page/update?access_token={0}", accessToken);
				var data = new
				{
					page_id = pageId,
					title = title,
					description = description,
					page_url = pageUrl,
					comment = comment,
					icon_url = iconUrl
				};
				return CommonJsonSend.Send<UpdatePageResultJson>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static SearchPages_Data_Page SearchPagesByPageId(string accessTokenOrAppId, long[] pageIds, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<SearchPages_Data_Page>(delegate(string accessToken)
			{
				var data = new
				{
					page_ids = pageIds
				};
				return CommonJsonSend.Send<SearchPages_Data_Page>(accessToken, ShakeAroundApi.searchPageUrl, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static SearchPages_Data_Page SearchPagesByRange(string accessTokenOrAppId, int begin, int count, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<SearchPages_Data_Page>(delegate(string accessToken)
			{
				var data = new
				{
					begin,
					count
				};
				return CommonJsonSend.Send<SearchPages_Data_Page>(accessToken, ShakeAroundApi.searchPageUrl, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static WxJsonResult DeletePage(string accessTokenOrAppId, long[] pageIds, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/shakearound/page/delete?access_token={0}", accessToken);
				var data = new
				{
					page_ids = pageIds
				};
				return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static WxJsonResult BindPage(string accessTokenOrAppId, DeviceApply_Data_Device_Identifiers deviceIdentifier, long[] pageIds, ShakeAroundBindType bindType, ShakeAroundAppendType appendType, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/shakearound/device/bindpage?access_token={0}", accessToken);
				var data = new
				{
					device_identifier = deviceIdentifier,
					page_ids = pageIds,
					bind = (int)bindType,
					append = (int)appendType
				};
				return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static GetShakeInfoResultJson GetShakeInfo(string accessTokenOrAppId, string ticket, int needPoi = 1, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<GetShakeInfoResultJson>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/shakearound/user/getshakeinfo?access_token={0}", accessToken);
				var data = new
				{
					ticket = ticket,
					need_poi = needPoi
				};
				return CommonJsonSend.Send<GetShakeInfoResultJson>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static StatisticsResultJson StatisticsByDevice(string accessTokenOrAppId, DeviceApply_Data_Device_Identifiers deviceIdentifier, long beginDate, long endDate, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<StatisticsResultJson>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/shakearound/statistics/device?access_token={0}", accessToken);
				var data = new
				{
					device_identifier = deviceIdentifier,
					begin_date = beginDate,
					end_date = endDate
				};
				return CommonJsonSend.Send<StatisticsResultJson>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static StatisticsResultJson StatisticsByPage(string accessTokenOrAppId, long pageId, long beginDate, long endDate, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<StatisticsResultJson>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/shakearound/statistics/page?access_token={0}", accessToken);
				var data = new
				{
					page_id = pageId,
					begin_date = beginDate,
					end_date = endDate
				};
				return CommonJsonSend.Send<StatisticsResultJson>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
	}
}
